<template>
	<view v-if="userInfo.user_type == 1">
		<simple-toolbar :title="$t('asset.trading.assetTrading1')">
			<view slot="content" class="mg-l-sm h-box">
				<el-radio v-model="radio" label="1">{{ $t('asset.trading.mentionMoney') }}</el-radio>
				<el-radio v-model="radio" label="2">{{ $t('asset.trading.earnings') }}</el-radio>
			</view>
		</simple-toolbar>

		<view class="pad-base table">
			<nav-tab @change-current-tab="getData" @ready="getData" />
			
			<el-table :data="listData" style="width: 100%">
				<el-table-column align="center" prop="user" :label="$t('asset.trading.id')"></el-table-column>
				<el-table-column align="center" prop="contract_num" :label="$t('asset.trading.contract')"></el-table-column>
				<el-table-column align="center" prop="coin_name" :label="$t('wallet.wallet.coin')">
					<!-- <template slot-scope="scope">
						<text>{{coinList[scope.row.coin - 1].coin_name}}</text>
					</template> -->
				</el-table-column>
				<el-table-column align="center" prop="amount" :label="$t('asset.trading.amount')"></el-table-column>
				<!-- <el-table-column align="center" prop="withdraw" :label="$t('asset.trading.mentionMoneyNum')" v-if="radio == 1"></el-table-column> -->
				<!-- <el-table-column align="center" prop="id" :label="$t('asset.trading.earningsNum')" v-else></el-table-column> -->
				<el-table-column align="center" :label="$t('asset.trading.type')">
					<template slot-scope="scope">
						<text>{{ scope.row.in_out == 'out' ? $t('asset.trading.mentionMoney') : $t('asset.trading.earnings') }}</text>
					</template>
				</el-table-column>
				<el-table-column align="center" prop="record_time" :label="$t('asset.trading.record_time')"></el-table-column>
			</el-table>
		</view>
	</view>

	<view v-else>
		<simple-toolbar :title="$t('asset.trading.assetTrading2')">
			<view slot="content" class="mg-l-sm h-box">
				<el-radio v-model="radio" label="1">{{ $t('asset.trading.mentionMoney') }}</el-radio>
				<el-radio v-model="radio" label="2">{{ $t('asset.trading.earnings') }}</el-radio>
			</view>
		</simple-toolbar>

		<view class="pad-base table">
			<nav-tab @change-current-tab="getData" @ready="getData" />
			
			<el-table :data="listData" style="width: 100%">
				<el-table-column align="center" prop="user" :label="$t('asset.trading.id')"></el-table-column>
				<el-table-column align="center" prop="contract_num" :label="$t('asset.trading.contract')"></el-table-column>
				<el-table-column align="center" prop="coin_name" :label="$t('wallet.wallet.coin')">
					<!-- <template slot-scope="scope">
						<text>{{coinList[scope.row.coin - 1].coin_name}}</text>
					</template> -->
				</el-table-column>
				<el-table-column align="center" prop="amount" :label="$t('asset.trading.amount')"></el-table-column>
				<el-table-column align="center" :label="$t('asset.trading.type')">
					<template slot-scope="scope">
						<text>{{ scope.row.in_out == 'out' ? $t('asset.trading.mentionMoney') : $t('asset.trading.earnings') }}</text>
					</template>
				</el-table-column>
				<!-- <el-table-column align="center" prop="withdraw" :label="$t('asset.trading.mentionMoneyNum')" v-if="radio == 1"></el-table-column> -->
				<!-- <el-table-column align="center" prop="pool_record" :label="$t('asset.trading.earningsNum')" v-else></el-table-column> -->
				<el-table-column align="center" prop="record_time" :label="$t('asset.trading.record_time')"></el-table-column>
			</el-table>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import {
		adminTrading,
		userTrading
	} from "../../../js_sdk/uni-admin/asset.js"

	export default {
		onShow() {
			// this.getData()
		},
		data() {
			return {
				cacheCurrentTab: {
					coin: 1
				},
				// coinList: [],
				listData: [],
				radio: '1'
			}
		},
		computed: {
			...mapState('user', ['userInfo'])
		},
		watch: {
			radio() {
				this.getData(this.data)
			}
		},
		methods: {
			editTrading(state, row) {
				uni.navigateTo({
					url: `./editTrading?state=${state}`
				})
			},
			async getData(data) {
				this.data = data
				// this.coinList = uni.getStorageSync('coinList')
				let res = undefined
				let query = {}
				if (data) {
					query = data
					this.cacheCurrentTab = data
				} else {
					query = this.cacheCurrentTab
				}
				// query.is_deposit = this.radio == '1' ? 'True' : 'False'
				query.in_out = this.radio == '1' ? 'out' : 'in'
				if (this.userInfo.user_type == 1) {
					res = await adminTrading('get', query)
				} else {
					res = await userTrading('get', query)
				}
				this.listData = res.data
				this.listData.forEach(item => {
					item.amount = this.$utils.retain12(item.amount)
					item.record_time = this.$utils.formatDate(item.record_time)
				})
			}
		}
	}
</script>

<style>

</style>
